import java.sql.SQLOutput;
import java.util.Arrays;

class Person {
    String name;
    int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class Test {
    public static void main(String[] args) {
        final int[] array = {1,2,3,4,5};
        array[0] = 100;
        System.out.println(array[0]);
        //array = new int[10];不能够修改这个引用的指向
    }
    public static void main12(String[] args) {
        String str1 = " j   da skdf asd ";
        String ret1 = str1.trim();
        System.out.println(ret1);
        System.out.println(str1);
        System.out.println(str1.toUpperCase());
        System.out.println(str1.toLowerCase());
    }
    public static void main11(String[] args) {
        //字符串截取:左闭右开
        String str1 = "hello";
        String ret1 = str1.substring(2);
        System.out.println(ret1);
        String ret2 = str1.substring(1,3);
        System.out.println(ret2);
    }
    public static void main10(String[] args) {
        //根据指定的字符将字符串分割
        String str = "hello_world_and_yang";
        String[] ret = str.split("_",2);
        for(int i = 0; i < ret.length; i++) {
            System.out.println(ret[i]);
        }
        String str2 = "192.168.1.0";
        String[] ret2 = str2.split("\\.");
        for(int i = 0; i < ret2.length; i++) {
            System.out.println(ret2[i]);
        }
        String str3 = "192\\168\\1\\0";
        String[] ret3 = str3.split("\\\\");
        for(int i = 0; i < ret3.length; i++) {
            System.out.println(ret3[i]);
        }

        //多次拆分
        String str4 = "yang=shi&ge=shen";
        String[] ret4 = str4.split("&|=");
        for(int i = 0; i < ret4.length; i++) {
            System.out.println(ret4[i]);
        }
        //多次拆分
        String str5 = "yang=shi&ge=shen";
        String[] ret5 = str5.split("&|=");
        for(int i = 0; i < ret5.length; i++) {
//            System.out.println(ret5[i]);
            String[] strings = ret5[i].split("=");
            for(String s : strings) {
                System.out.println(s);
            }
        }
    }
    public static void main9(String[] args) {
        //字符串替换
        String str1 = "ashjdfabab";
        String ret1 = str1.replaceFirst("ab", "33");
        System.out.println(ret1);
        String ret2 = str1.replaceAll("ab","lll");
        System.out.println(ret2);
        String ret3 = str1.replace("a","eee");
        System.out.println(ret3);
        String ret4 = str1.replace('a','s');
        System.out.println(ret4);
    }
    public static void main8(String[] args) {
        int[] array = {1,2,3,4,5,6};
        System.out.println(add(array));
    }
    public static int add(int a, int b) {
        return a+b;
    }
    public static int add(int a, int b, int c) {
        return a+b+c;
    }
    //可变参数列表
    public static int add(int... args) {
        int ret = 0;
        for (int i = 0; i < args.length; i++) {
            ret += args[i];
        }
        return ret;
    }
    public static void main7(String[] args) {
        String ret2 = String.format("%.2f,%d",10.234,23);
        System.out.println(ret2);
    }
    public static void main6(String[] args) {
        //使用多
        String str1 = "hello world";
        char[] array = str1.toCharArray();
        System.out.println(Arrays.toString(array));
    }
    public static void main5(String[] args) {
        //所有对String的修改，都不是在原来值的基础上修改的
        String str1 = "helLo";
        String ret = str1.toUpperCase();
        System.out.println(ret);
        System.out.println(str1.toLowerCase());
    }
    public static void main4(String[] args) {
        //boolean,int,float,double,long,char类型转字符串
        String str1 = String.valueOf(1234);
        String str = String.valueOf(true);

        System.out.println(str);

        String str2 = String.valueOf(new Person("zhangs",12));
        System.out.println(str2);

        //字符串转int
        int data1 = Integer.valueOf("123");
        int data2 = Integer.parseInt("1234");
        System.out.println(data2);
        System.out.println(data1);
    }
    public static void main3(String[] args) {
        String str1 = "hello";
        //char charAt(int index):返回index位置上的字符，位置非法则抛出异常
        char ch = str1.charAt(1);
        System.out.println(ch);
        //int indexOf(int ch):返回ch第一次出现的位置，无则返回-1
        System.out.println(str1.indexOf('l'));
        //int indexOf(int ch,int num):从num位置开始查找第一个出现ch字符的位置
        System.out.println(str1.indexOf('l', 3));
        //int indexOf(String str):返回str第一次出现的位置，无则返回-1
        System.out.println(str1.indexOf("ll"));
        //int indexOf(String str,int num):从num位置开始查找第一次出现str的位置
        System.out.println(str1.indexOf("ll",2));
        //int lastIndexOf(int ch):从后往前找，返回ch第一次出现的位置，没有返回-1
        System.out.println(str1.lastIndexOf('l'));
        //int lastIndexOf(int ch, int num):从num开始找，从后往前第一个出现ch的位置，没有返回-1
        System.out.println(str1.lastIndexOf('l', 3));
        //int lastIndexOf(String str):从后往前找第一次出现str的位置，没有返回-1
        System.out.println(str1.lastIndexOf("ll"));
        //int lastIndexOf(String str, int num):从num开始找，从后往前第一次出现str的位置，没有返回-1
        System.out.println(str1.lastIndexOf("ll",0));
    }
    public static void main2(String[] args) {
        String str1 = new String("hello");
        String str2 = "hello";
        System.out.println(str1 == str2);//变量地址的比较
        System.out.println(str1.equals(str2));
        System.out.println("======");
        String str3 = "abc";
        String str4 = "abc";
        System.out.println(str3 == str4);//true
        System.out.println("======");
        String str5 = "dfsa";
        String str6 = "dfSa";
        //比较字符串大小
        System.out.println(str5.compareTo(str6));
        //比较字符串大小忽略大小写
        System.out.println(str5.compareToIgnoreCase(str6));
    }
    public static void main1(String[] args) {
        String str1 = "hello"; //1. 使用常量构造
        String str2 = new String("world");//2.直接newString对象
        char[] chars = {'a','b','c'};//3.使用字符数组进行构造
        String str3 = new String(chars);
        System.out.println(str3);
        System.out.println(str1.length());
        System.out.println(str2.isEmpty());

        String str4 = ""; //str4指向的对象当中没有任何数据
        System.out.println(str4.isEmpty());
        String str5 = null; //str5不指向任何对象
        System.out.println(str5.isEmpty());
    }
}
